package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsDeviceOperateLogQueryPageRequest;
import com.sgzn.sgpay.model.request.util.PageQueryParam;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.result.DeviceOperateLogQueryPageResult;
import com.sgzn.sgpay.service.SgsDeviceOperateLogService;
import com.sgzn.sgpay.web.controller.base.MerchantBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.DeviceOperateLogQueryPageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 设备日志操作记录控制器
 * @author huangsenguang
 * @version Id: DeviceOperateLogController.java, v 0.1 2018/6/19 8:39 huangsenguang Exp $$
 */
@Slf4j
@Controller
@RequestMapping("/merchant/deviceOperateLog")
public class DeviceOperateLogController extends MerchantBaseController {

    @Autowired
    private SgsDeviceOperateLogService sgsDeviceOperateLogService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    /**
     * 分页查询设备日志操作记录
     * @param request
     * @return
     */
    @RequestMapping("queryPage")
    @ResponseBody
    public SgsResultResponse<DeviceOperateLogQueryPageResult> queryPageDeviceOperateLog(DeviceOperateLogQueryPageRequest request) {
        super.setMchInfo(request);
        return this.sgsDeviceOperateLogService.queryPage(assembleQueryPageRequest(request));
    }

    /**
     * 组装服务请求
     * @param request
     * @return
     */
    private SgsDeviceOperateLogQueryPageRequest assembleQueryPageRequest(DeviceOperateLogQueryPageRequest request) {
        SgsDeviceOperateLogQueryPageRequest sgsDeviceOperateLogQueryPageRequest = new SgsDeviceOperateLogQueryPageRequest();
        this.assembleCommonHandle.assemble(request, sgsDeviceOperateLogQueryPageRequest);
        sgsDeviceOperateLogQueryPageRequest.setDeviceId(request.getDeviceId());
        sgsDeviceOperateLogQueryPageRequest.setShopName(request.getShopName());
        PageQueryParam pageQueryParam = new PageQueryParam();
        pageQueryParam.setPageSize(Integer.parseInt(request.getPageSize()));
        pageQueryParam.setCurrentPage(Integer.valueOf(request.getPageNum()));
        sgsDeviceOperateLogQueryPageRequest.setPageQueryParam(pageQueryParam);
        return sgsDeviceOperateLogQueryPageRequest;
    }

}

